﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace DemoApp3.Models
{
    public class AppConfig
    {
        // Server Parts
        public static string AuthorizationServerBaseAddress { get; private set; }

        public static string ResourceServerAPIAddress { get; private set; }

        public static string AjaxCallAuthAddress { get; private set; }

        public static string AuthenticationType { get; private set; }

        public static string AuthorizePath { get; private set; }

        public static string TokenPath { get; private set; }

        public static string LoginPath { get; private set; }

        public static string LogoutPath { get; private set; }

        public static int SessionLoginTimeOut { get; private set; }

        public static int PersistentLoginTimeOut { get; private set; }

        public static int AccessTokenTimeOut { get; private set; }

        public static bool AllowInsecureHttp { get; private set; }

        // Client Parts
        public static string ClientId { get; private set; }

        public static string ClientSecret { get; private set; }

        public static string ResponseType { get; private set; }

        public static string GrantType { get; private set; }

        public static string GrantTypeForRefreshToken { get; private set; }

        public static string RedirectUri { get; private set; }

        public static string ClientReturnUrlCookieName { get; private set; }

        public static string AccessTokenCookieName { get; private set; }

        public static string RefreshedAccessTokenCookieName { get; private set; }

        public static string HeaderNameForAjaxAuth { get; private set; }

        public static void Configure()
        {
            // Server Parts
            AuthorizationServerBaseAddress = ConfigurationManager.AppSettings.Get("AuthorizationServerBaseAddress");

            ResourceServerAPIAddress = ConfigurationManager.AppSettings.Get("ResourceServerAPIAddress");

            AjaxCallAuthAddress = ConfigurationManager.AppSettings.Get("AjaxCallAuthAddress");

            AuthenticationType = ConfigurationManager.AppSettings.Get("AuthenticationType");

            AuthorizePath = ConfigurationManager.AppSettings.Get("AuthorizePath");

            TokenPath = ConfigurationManager.AppSettings.Get("TokenPath");

            LoginPath = ConfigurationManager.AppSettings.Get("LoginPath");

            LogoutPath = ConfigurationManager.AppSettings.Get("LogoutPath");

            SessionLoginTimeOut = ConfigurationManager.AppSettings.Get("SessionLoginTimeOut") != null ? int.Parse(ConfigurationManager.AppSettings.Get("SessionLoginTimeOut")) : 60;

            PersistentLoginTimeOut = ConfigurationManager.AppSettings.Get("PersistentLoginTimeOut") != null ? int.Parse(ConfigurationManager.AppSettings.Get("PersistentLoginTimeOut")) : 7 * 24 * 60;

            AccessTokenTimeOut = ConfigurationManager.AppSettings.Get("AccessTokenTimeOut") != null ? int.Parse(ConfigurationManager.AppSettings.Get("AccessTokenTimeOut")) : 3;

            AllowInsecureHttp = ConfigurationManager.AppSettings.Get("AllowInsecureHttp") != null ? bool.Parse(ConfigurationManager.AppSettings.Get("AllowInsecureHttp")) : true;

            // Client Parts
            ClientId = ConfigurationManager.AppSettings.Get("ClientId");

            ClientSecret = ConfigurationManager.AppSettings.Get("ClientSecret");

            ResponseType = ConfigurationManager.AppSettings.Get("ResponseType");

            GrantType = ConfigurationManager.AppSettings.Get("GrantType");

            GrantTypeForRefreshToken = ConfigurationManager.AppSettings.Get("GrantTypeForRefreshToken");

            RedirectUri = ConfigurationManager.AppSettings.Get("RedirectUri");

            ClientReturnUrlCookieName = ConfigurationManager.AppSettings.Get("ClientReturnUrlCookieName");

            AccessTokenCookieName = ConfigurationManager.AppSettings.Get("AccessTokenCookieName");

            RefreshedAccessTokenCookieName = ConfigurationManager.AppSettings.Get("RefreshedAccessTokenCookieName");

            HeaderNameForAjaxAuth = ConfigurationManager.AppSettings.Get("HeaderNameForAjaxAuth");
        }
    }
}